    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
function changeSate(id, state) {
    $.ajax({
        type: 'POST',
        url: "changeState",
        data: {
            id: id,
            state: state
        },
        success: function () {
            $('#mytable').bootstrapTable('refresh', {url: '/admin/saccount/list'});
        },
        dataType: "json"
    });
}

function deleteOne(id) {
    swal({
        title: '您确定要删除此行数据？',
        text: '你将无法恢复它！',
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#ed5666',
        confirmButtonText: '确定删除！',
        cancelButtonText: '取消删除！',
        confirmButtonClass: 'btn btn-success',
        cancelButtonClass: 'btn btn-danger',
        buttonsStyling: false
    }).then(function () {
        $.ajax({
            type: 'POST',
            url: "deleteOne",
            data: {
                id: id,
            },
            success: function (status) {
                if (status == 1) {
                    swal({title: "删除成功", text: "", type: "success"})
                    $('#mytable').bootstrapTable('refresh', {url: '/admin/saccount/list'});
                } else {
                    swal({title: "删除失败", text: "", type: "error"})
                }
            },
            dataType: "json"
        });

    }, function (dismiss) {
        // dismiss的值可以是'cancel', 'overlay',
        // 'close', 'timer'
        if (dismiss === 'cancel') {
            swal({title: '您已取消操作！', text: '', timer: 2000})
        }
    })
}

var editsw=[];
/**
 * 为模态框填充数据
 */
$('#modal-form').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget); // 触发事件的按钮
    var id = button.data('row');
    console.log(button.data('row'))
    var modal = $(this);
    $.ajax({
        type: 'POST',
        url: "getSaccountById",
        data: {
            id: id
        },
        success: function (data) {
            console.log(data)
                                                modal.find('#sid').val(data.sid)
                                                                modal.find('#amount').val(data.amount)
                                                                modal.find('#saleAmount').val(data.saleAmount)
                                                                modal.find('#mamount').val(data.mamount)
                                                                modal.find('#youhui').val(data.youhui)
                                                                modal.find('#fanli').val(data.fanli)
                                                                modal.find('#fanliing').val(data.fanliing)
                                                                modal.find('#total').val(data.total)
                                                                modal.find('#freeze').val(data.freeze)
                                                                modal.find('#chargeAmount').val(data.chargeAmount)
                                                                modal.find('#withdraw').val(data.withdraw)
                                                                modal.find('#unuseAmount').val(data.unuseAmount)
                                                                modal.find('#consume').val(data.consume)
                                                                modal.find('#refund').val(data.refund)
                                                                modal.find('#jifen').val(data.jifen)
                                                                editsw["isIndependentPay"] == undefined ? editsw["isIndependentPay"] = new Switchery(document.querySelector('#isIndependentPay'), {color: "#1AB394"}) : ""
                    if (data.isMember == 1) {
                        setSwitchery(editsw["isIndependentPay"], true);
                    } else {
                        setSwitchery(editsw["isIndependentPay"], false);
                    }
                                                                editsw["state"] == undefined ? editsw["state"] = new Switchery(document.querySelector('#state'), {color: "#1AB394"}) : ""
                    if (data.isMember == 1) {
                        setSwitchery(editsw["state"], true);
                    } else {
                        setSwitchery(editsw["state"], false);
                    }
                                                                modal.find('#phone').val(data.phone)
                                                                modal.find('#version').val(data.version)
                                                                modal.find('#smsmoutTotal').val(data.smsmoutTotal)
                                                                modal.find('#smsmout').val(data.smsmout)
                                                                modal.find('#smstotal').val(data.smstotal)
                                                                modal.find('#smsprice').val(data.smsprice)
                                                                                                                                                        modal.find('#leagueid').val(data.leagueid)
                                                                                                            modal.find('#unionid').val(data.unionid)
                                                                                                                                                        modal.find('#modifier').val(data.modifier)
                            
            if(data.state==1){
                modal.find('#state').attr("checked",'checked').val("1");
            }
        },
        dataType: "json"
    });
})

//tableHeight函数
function tableHeight(){
    //可以根据自己页面情况进行调整
    return $(window).height() -200;
}
$(function() {
    var sw = [];
    $(".js-switch").each(function (i,e) {
        sw[i] = new Switchery(e, {color: "#1AB394"})
    })

    $(window).resize(function () {
        $('#mytable').bootstrapTable('resetView', {
            height: tableHeight()
        })
    })

    //生成用户数据
    $('#mytable').bootstrapTable({
        method: 'get',
        url:"/admin/saccount/list",
        // height:520,//高度调整
        // toolbar: '#toolbar',
        striped: true, //是否显示行间隔色
        dataField: "records",
        pagination:true,//是否分页
        queryParamsType:'limit',
        queryParams:queryParams,
        sidePagination:'server',
        pageNumber: 1, //初始化加载第一页，默认第一页
        pageSize:50,//单页记录数
        pageList:[50,100,200,500],//分页步进值
        showExport:true,//显示导出
        showRefresh:false,//刷新按钮
        showColumns:false,
        clikToSelect: true,//是否启用点击选中行
        // toolbarAlign:'right',
        // buttonsAlign:'right',//按钮对齐方式
        columns:[
             {
                 title:'全选',
                 field:'select',
                 checkbox:true,
                 width:25,
                 align:'center',
                 valign:'middle'
            },
            {
                title:'ID',
                field:'id',
                visible:false
            },
                                                                                                    {
                            title:'可用金额#可用金额=可提现金额=累计充值余额+累计销售额-押金-待入账销售额-消耗金额-累计提现额-营销金额&',
                            field:'amount'
                        },
                                                                                                            {
                            title:'累计销售额#累计销售额=累计(销售额=单价*数量)&',
                            field:'saleAmount'
                        },
                                                                                                            {
                            title:'营销金额#营销金额=营销成本=积分抵扣+会员卡抵扣+优惠券抵扣+红包抵扣+快递费用&',
                            field:'mamount'
                        },
                                                                                                            {
                            title:'商家总优惠金额',
                            field:'youhui'
                        },
                                                                                                            {
                            title:'累计佣金',
                            field:'fanli'
                        },
                                                                                                            {
                            title:'待入账佣金&',
                            field:'fanliing'
                        },
                                                                                                            {
                            title:'总金额#总金额=不可用金额+可用金额=累计充值余额+累计销售额',
                            field:'total'
                        },
                                                                                                            {
                            title:'冻结资金=押金&',
                            field:'freeze'
                        },
                                                                                                            {
                            title:'累计充值余额&',
                            field:'chargeAmount'
                        },
                                                                                                            {
                            title:'累计提现额&',
                            field:'withdraw'
                        },
                                                                                                            {
                            title:'不可用金额#不可用金额=待入账销售额+冻结资金&',
                            field:'unuseAmount'
                        },
                                                                                                            {
                            title:'消耗金额#消耗金额=广告费用=推广费用&',
                            field:'consume'
                        },
                                                                                                            {
                            title:'总退款额',
                            field:'refund'
                        },
                                                                                                            {
                            title:'积分',
                            field:'jifen'
                        },
                                                                                                            {
                            title:'是否独立支付',
                            field:'isIndependentPay'
                        },
                                                                                                            {
                            title:'启用状态&',
                            field:'state',
                            formatter:"stateFormatter"
                        },
                                                                                                            {
                            title:'手机号&',
                            field:'phone'
                        },
                                                                                                                                        {
                            title:'累计短信充值费用',
                            field:'smsmoutTotal'
                        },
                                                                                                            {
                            title:'短信余额',
                            field:'smsmout'
                        },
                                                                                                            {
                            title:'剩余短信条数',
                            field:'smstotal'
                        },
                                                                                                            {
                            title:'短信价格',
                            field:'smsprice'
                        },
                                                                                                                                                                                                                                                                                            {
                title:'操作',
                field:'Attribute',
                align:'center',
                formatter:actionFormatter
            }
        ],
        locale:'zh-CN',//中文支持,
    })

    //请求服务数据时所传参数
    function queryParams(params){
        console.log(params)
        return params;
    }

})